<template>
	<view>
		<!-- Tab选择 -->
<!-- 		<scroll-view scroll-x class="bg-white nav">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="'all' == tabCur ? 'text-blue cur' : ''" @tap="tabSelect" data-id="all">
					全部证书
				</view>

				<view class="cu-item flex-sub" :class="0 == tabCur ? 'text-blue cur' : ''" @tap="tabSelect" :data-id="0">
					培训计划
				</view>

				<view class="cu-item flex-sub" :class="1 == tabCur ? 'text-blue cur' : ''" @tap="tabSelect" :data-id="1">
					课程结业
				</view>

				<view class="cu-item flex-sub" :class="2 == tabCur ? 'text-blue cur' : ''" @tap="tabSelect" :data-id="2">
					完成考试
				</view>
			</view>
		</scroll-view> -->

		<!-- 证书列表 -->
		<view class="">			
			<view class="course_list">
				<view class="course_item" v-for="(v,k) in list" :key="k">
					<view class="course_img" @click="openModal(v.path)">
						<image :src="BASE_URL+v.path" mode="aspectFill" @tap="previewImage(v,k)"></image>
					</view>
					<!-- 证书信息部分 -->
					<view class="course_r">
						<!-- 用户姓名 -->
						<!-- <view class="course_title">
							证书标题: {{ v.certificate_title }}
						</view> -->

						<!-- 部门信息 -->
						<!-- <view class="course_department">
							证书编号: {{ v.certificate_number }}
						</view> -->

						<!-- 颁发时间 -->
						<view class="course_time">
							颁发时间: {{ v.issued_time }}
						</view>

						<!-- 证书名称 -->
						<!-- <view class="course_cert_name">
							认证机构: {{ v.issuing_authority }}
						</view> -->
					</view>
				</view>			
			</view>

			<!-- 加载状态条 -->
			<view class="cu-load" :class="loadFlag" v-show="!has_more"></view>
		</view>
		
		<!-- Full image modal -->
		<view v-if="isImageModalVisible" class="image-modal" @click="closeModal">
		  <image :src="fullImageSrc" mode="aspectFit"></image>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			tabCur: 'all',  // 默认选中"全部证书"标签
			list: [],       // 存储证书列表数据
			has_more: false,  // 是否还有更多数据
			current_page: 1,  // 当前页码
			loadFlag: 'loading',  // 加载状态标识			
			isImageModalVisible: false,  // 控制图片弹窗的显示
			fullImageSrc: '',           // 存储完整图片的路径
			BASE_URL:this.$BASE_URL
		};
	},
	computed: {
		// 获取标签样式，根据状态返回不同颜色
		getTagStyle() {
			return function(item) {
				let style = {
					text: item.status_text,
					size: 24
				};
				switch (parseInt(item.status)) {
					case 0:
						style.color = '#f37b1d'; // 培训计划的颜色
						break;
					case 1:
						style.color = '#39b54a'; // 课程结业的颜色
						break;
					case 2:
						style.color = '#e54d42'; // 完成考试的颜色
						break;
				}
				return style;
			};
		}
	},
	onLoad() {
		this.getList();  // 页面加载时获取数据
	},
	async onReachBottom() {
		// 下拉加载更多数据
		if (this.has_more) {
			this.current_page++;
			this.getList();  // 加载下一页数据
		}
	},
	methods: {
		// 获取证书列表数据
		getList() {
			this.http('Cert/index', {
				page: this.current_page,
				status: this.tabCur  // 根据选中的tab筛选
			}, 'get').then(res => {
				if (res && res.data) {
					if (this.current_page == 1) {
						this.list = res.data.list.data;  // 如果是第一页，重置列表
					} else {
						this.list = [...this.list, ...res.data.list.data];  // 否则追加数据
					}
					this.has_more = res.data.list.has_more;  // 判断是否有更多数据
					this.current_page = res.data.list.current_page;  // 更新当前页码
					this.loadFlag = 'over';  // 加载完成
				}
			});
		},

		openModal(imagePath) {
		  this.modalImage = imagePath; // 获取图片路径
		  this.isModalVisible = true; // 显示模态框
		},
		closeModal() {
		  this.isModalVisible = false; // 隐藏模态框
		},
		// Tab切换事件
		tabSelect(e) {
			this.tabCur = e.currentTarget.dataset.id;  // 切换Tab
			this.current_page = 1;  // 重置为第一页
			this.getList();  // 重新获取数据
		},

		// 跳转到详细页面
		goDetail(id) {
			uni.navigateTo({
				url: 'detail?id=' + id,
			});
		},
		
		/**
		 * 图片预览
		 */
		previewImage(item, index) {
			uni.previewImage({
				urls: [this.BASE_URL+item.path],
				current: 0
			})
		}
	}
};
</script>

<style>
	.paper-contains {
		margin-top: 50px;
	}

	.paper-card {
		margin: 20rpx 0;
	}

	.tui-title {
		width: 100%;
		padding: 70rpx 30rpx 30rpx 30rpx;
		box-sizing: border-box;
		font-size: 30rpx;
		line-height: 30rpx;
		color: #666;
	}

	.tui-default {
		padding: 20rpx 30rpx;
	}

	.tui-article {
		position: relative;
	}

	.tui-article-img {
		width: 100%;
		height: 300rpx;
		display: block;
	}

	.tui-article-title {
		position: absolute;
		left: 0;
		bottom: 0;
		color: #fff;
		font-size: 32rpx;
		font-weight: 500;
		box-sizing: border-box;
		padding: 20rpx 30rpx;
		background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.6));
	}

	.tui-cell-title {
		font-size: 32rpx;
		font-weight: 500;
		padding: 0 10rpx;
		word-break: break-all;
		word-wrap: break-word;
	}

	.tui-cell-img {
		height: 160rpx;
		width: 160rpx;
	}

	.tui-flex {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.tui-mr {
		margin-right: 20rpx;
	}


	.tui-flex-pic {
		display: flex;
		display: -webkit-flex;
		justify-content: space-between;
		flex-direction: row;
		flex-wrap: wrap;
		box-sizing: border-box;
		background: #fff;
		padding: 0 120rpx;
	}

	.tui-flex-pic image {
		width: 32%;
		margin-bottom: 2%;
	}

	.tui-content {
		padding: 0rpx 30rpx 20rpx 120rpx;
		box-sizing: border-box;
		font-size: 34rpx;
		font-weight: 400;
		color: #333;
	}

	.tui-color-gray {
		color: #ccc;
	}

	.tui-pleft {
		padding-left: 120rpx;
	}
	.course_list {
	    background-color: #fff;
	    margin: 20rpx; /* 列表整体边距 */
	}
	
	.course_item {
	    display: flex;
	    margin-top: 20rpx;
	    border-bottom: 1px dashed #dcdcdc;
	    padding-bottom: 20rpx;
	    padding-left: 20rpx;
	    padding-right: 20rpx;
	}
	/* Container styles */
	.course_list {
	  padding: 15px;
	  background: #fff;
	}
	
	/* Individual course item */
	
	.course_item {
		flex-direction: column;
	}

	.course_img,.course_r {
		width: 100%;
	}

	/* Individual course item */
	.course_item {
	  margin-bottom: 20px;
	  padding: 15px;
	  background: #fff;
	}
	
	/* Image styling */
	.course_img image {
		width: 300px;
		height: 200px;
	}
	.course_img {
		margin-right: 0;
		margin-bottom: 15px;
	}
	/* Right side information container */
	.course_r {
	  display: flex;
	  flex-direction: column;
	  justify-content: space-between;
	}
	
	/* Title styling */
	.course_title {
	  font-size: 14px;
	  color: #666;
	  margin-bottom: 8px;
	}
	
	/* Department info */
	.course_department {
	  font-size: 14px;
	  color: #666;
	  margin-bottom: 8px;
	}
	
	/* Time display section */
	.course_time {
	  font-size: 14px;
	  color: #666;
	  margin-bottom: 8px;
	}
	
	/* Certificate name */
	.course_cert_name {
	  font-size: 14px;
	  color: #666;
	}
	
	/* Line clamp utility */
	.line_2 {
	  display: -webkit-box;
	  -webkit-line-clamp: 2;
	  -webkit-box-orient: vertical;
	  overflow: hidden;
	}
	
	/* Loading state */
	.cu-load {
	  text-align: center;
	  padding: 15px;
	  color: #999;
	}
	
	/* 弹窗样式 */
	.image-modal {
	  position: fixed;
	  top: 0;
	  left: 0;
	  right: 0;
	  bottom: 0;
	  background-color: rgba(0, 0, 0, 0.8); /* 半透明背景 */
	  display: flex;
	  justify-content: center;
	  align-items: center;
	}
	
	.image-modal image {
	  max-width: 90%;  /* 设置弹窗中图片的最大宽度 */
	  max-height: 90%; /* 设置弹窗中图片的最大高度 */
	}
</style>
